<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function getData1(){
				let xhr=new XMLHttpRequest()
				xhr.open("GET","info.txt",false)
				xhr.send()
				let data=xhr.responseText
				document.getElementById("1").textContent=data
			}
			function getData2(){
				let xhr=new XMLHttpRequest
				xhr.open("GET","info.txt",true)
				xhr.send()
				xhr.onreadystatechange = function(){
					if(xhr.readyState==4 && xhr.status==200){
						let data = xhr.responseText //以文本的方式来接收数据
						document.getElementById("2").textContent = data
					}
				}
			}
		</script>
	</head>
	<body>
		点击按钮获得into.txt的文本数据（同步请求）<br>
		<button type="button" onclick="getData1()">获取信息</button><br>
		获得的信息：<span id="1" style="color: red;"></span><br>
		<hr >
		点击按钮获得into.txt的文本数据（异步请求）<br>
		<button type="button" onclick="getData2()">获取信息</button><br>
		获得的信息：<span id="2" style="color: red;"></span><br>
	</body>
</html>
